/*
 * @Author: jiu yin
 * @Date: 2023-04-27 14:58:00
 * @LastEditTime: 2023-06-02 10:01:28
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \AI admin\src\router\index.tsx
 * jiu
 */
import { Navigate, useRoutes } from "react-router-dom";
import React, { useEffect } from "react";
import lazyLoad from "@/router/utlis/lazy";

import { useSelector, useDispatch } from 'react-redux'
import routerArr from "./routerArr";


function Router() {


	let arr = [
		{
			path: "/login",
			element: lazyLoad(React.lazy(() => import("@/view/login"))),
			meta: {
				name: "登录",
				icon: "HighlightOutlined"
			},
		},
		{
			path: "/404",
			element: lazyLoad(React.lazy(() => import("@/comment/404"))),
			meta: {
				name: "404",
				icon: "HighlightOutlined"
			},
		},
		{
			path: "*",
			element: <Navigate to="/404" />
		},
		...routerArr
	]



	let [routers, setRouters] = React.useState(arr)

	const asyncRouter = useSelector((state: any) => state.asyncRouter)
	useEffect(() => {
		setRouters(()=>routers.filter(item=>item.path!=="/404"))
	}, [asyncRouter])


	

	return useRoutes(routers);
}
export default Router;
